#ifndef _ECMFS_CONFIG_FILE_
#define _ECMFS_CONFIG_FILE_

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#ifdef HAVE_SETXATTR
#include <sys/xattr.h>
#endif
#include <getopt.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include "ecmfs_cmn.h"

#define CONF_VAR_LEN 32
#define CONF_VALUE_LEN 100
#define CONF_SEPERATOR '='
#define CONF_LINE_LEN (CONF_VAR_LEN + CONF_VALUE_LEN + 2)
#define MAX_CONF_VAR 100

typedef struct config_line_ {
    char confVar[CONF_VAR_LEN];
    char confValue[CONF_VALUE_LEN];    
} config_line_t;

typedef enum config_node_type_ {
    CONFIG_NONE = 0,
    CONFIG_CLIENT,
    CONFIG_EDGE,
    CONFIG_CORE,
    CONFIG_MASTER,
} config_node_type_t;

typedef enum config_parse_ret_ {
    CONFIG_FILE_READ_OK = 0,
    CONFIG_FILE_WRITE_OK = 0,
    CONFIG_FILE_ADD_OK = 0,
    CONFIG_FILE_SUCCESS = 0,
    CONFIG_FILE_NOT_FOUND,
    CONFIG_FILE_ERROR
} config_file_parse_ret_t;

typedef struct config_file {
        FILE *fd;
        config_line_t lines[MAX_CONF_VAR];
	char my_config_file[100];
	char my_ip[32];
	char password[32];
	char my_name[32];	
	char db_name[32];	
	char db_host[100];
	char db_login[32];
	char db_password[32];	
	char keystore_path[100];	
	char master_ip[32];	
	char hostfs_path[100];	
	int  master_port;	
	int  my_port;
	int  my_node_type;
	int  read_line;
	int  write_line;
	int  total_lines;
} config_file_t;
extern config_file_t *cfile;
config_file_parse_ret_t config_file_init(config_file_t *this, const char *config_file_name);
config_file_parse_ret_t cfg_open(config_file_t *this,
		     const char *config_file_name,
                     const char *mode);
config_file_parse_ret_t cfg_ropen(config_file_t *this,
		     const char *config_file_name);
config_file_parse_ret_t cfg_wopen(config_file_t *this,
		     const char *config_file_name);
config_file_parse_ret_t cfg_aopen(config_file_t *this,
		     char *config_file_name);
config_file_parse_ret_t cfg_rwopen(config_file_t *this,
		     char *config_file_name);
config_file_parse_ret_t cfg_close(config_file_t *this);
config_file_parse_ret_t cfg_read_file(config_file_t *this);
config_file_parse_ret_t cfg_write_file(config_file_t *this);

config_file_parse_ret_t cfg_read_line(config_file_t *this,
				config_line_t *line);
config_file_parse_ret_t cfg_write_line(config_file_t *this,
				config_line_t *line);
config_file_parse_ret_t cfg_add_to_list(config_file_t *this, 
				config_line_t *line);

#endif
